package itheima_07;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

//Collect集合储存学生对象并遍历
public class CollectDemo04 {
    public static void main(String[] args) {
        //创建Collection集合对象
        Collection<Student> c = new ArrayList<Student>();

        //创建学生对象
        Student s1 = new Student("林青霞", 30);
        Student s2 = new Student("张曼玉", 35);
        Student s3 = new Student("王祖贤", 33);
        //将学生添加到集合
        c.add(s1);
        c.add(s2);
        c.add(s3);
        //遍历集合
        Iterator<Student> it = c.iterator();
        while (it.hasNext()) {
            Student next = it.next();
            System.out.println(next.getName() + "," + next.getAge());
        }
    }
}
